<!-- delete_post.php -->
<?php
session_start();

// 数据库连接
$conn = new mysqli("localhost", "root", "", "db");
if ($conn->connect_error) {
    die("数据库连接失败: " . $conn->connect_error);
}

// 检查是否为DELETE请求
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
    $post_id = isset($_GET['id']) ? intval($_GET['id']) : null;
    if ($post_id !== null) {
        $sql = "DELETE FROM posts WHERE id = ?";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("i", $post_id);
        $stmt->execute();
        
        if ($stmt->affected_rows > 0) {
            echo json_encode(['success' => true]);
        } else {
            http_response_code(404);
            echo json_encode(['success' => false, 'message' => '动态未找到']);
        }
    } else {
        http_response_code(400);
        echo json_encode(['success' => false, 'message' => '无效的动态ID']);
    }
} else {
    http_response_code(405);
    echo json_encode(['success' => false, 'message' => '仅支持DELETE方法']);
}

$conn->close();
?>